<?
	
	require("class.phpmailer.php");
	function chkishotmail($email)
	{
		$email=strtoupper($email);
	
		$split=split("@",$email);
		$part2=split("\.",$split[1]);
		$domain=$part2[0];
		if($domain=="HOTMAIL")
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	
	function email_header($os_url,$logo_url,$websiteame_eng,$contact_number,$fax,$title)
	{
		$get_info=mysql_query("select website_name from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
	
		
		$out_put=
		"
		<html>
		<head>
		
		</head>
		
		<body >
		<table id='Table_01' width='629' height='699' border='0' cellpadding='0' cellspacing='0' bgcolor='#ffffff'>
			<tr>
				<td colspan='3' valign='bottom' height='20' ><img src='".$os_url."/images/email_template_01.png' align='bottom' style='display:block' ></td>
			</tr>
			<tr>
				<td bgcolor='#b1b1b1' width='10' ></td>
				<td  width='609'  valign='top' >
						<table width='600' bgcolor='#ffffff' align='center'>
							<tr valign='top'>
							<td align='left'>
							<font style='font-size:16px;color:#666666'><strong>".$websitename_eng."</strong></font><br>
							Tel: ".$contact_number."<br>
							Fax: ".$fax."<br>
							
							</td>
							<td align='right'><img src='".$logo_url."' width='200'></td>
							</tr>
							<tr>
								<td colspan='2' bgcolor='#000000' align='center' height='20'><font  style='color:#ffffff;font-size:14px;font-weight:bold'>".strtoupper($title)."</font></td>
							</tr>
							<tr>
								<td colspan='2' align='right'>";
					
		return $out_put;
		
	}
	
	function email_footer($os_url)
	{
		$out_put="	
								</td>
								<td bgcolor='#b1b1b1' width='10' height='100%'></td>
							</tr>
							<tr>
								<td colspan='3'>
									<img src='".$os_url."/images/email_template_05.png' width='629' height='28' alt=''></td>
							</tr>
						</table>
				</TD>
			</tr>
		</table>
		</body>
		</html>
		";
		
		return $out_put;
	}
	
	function servicepreferred2($type)
	{
		if($type==1)
		{
			return "C.O.D";
		}
		elseif($type==2)
		{
			return "Pos Express";
		}
		else
		{
			return "Pos Laju";
		}
		
	}
	
	function email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email)
	{
		

		$get_info=mysql_query("select email_host,email_username,email_password,email_fromname,email_reply from os_contactinfo where id=1")or die(mysql_error());
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		
		/*
		$mailer = new PHPMailer();
		$mailer = new PHPMailer();
		$mailer->IsSMTP();
		$mailer->isHTML(true);
		$mailer->Host = 'mail.dlookingglass.com:25';
		$mailer->SMTPAuth = TRUE;
		$mailer->Username = 'info@dlookingglass.com';  // Change this to your gmail adress
		$mailer->Password = 'd1gg1d';  // Change this to your gmail password
		$mailer->From = 'info@dlookingglass.com';  // This HAVE TO be your gmail adress
		$mailer->FromName = 'D Looking Glass Admin'; // This is the from name in the email, you can put anything you like here
		$mailer->Body = $body;
		$mailer->Subject = $subject;
		*/
		$mailer = new PHPMailer();
		$mailer->IsSMTP();
		$mailer->isHTML(true);
		$mailer->Host = $i["email_host"];
		$mailer->SMTPAuth = TRUE;
		$mailer->Username = $i["email_username"]; 
		$mailer->Password = $i["email_password"]; 
		$mailer->From = $i['email_reply'];  
		$mailer->FromName = $i['email_fromname']; 
		$mailer->Body = stripslashes($body);
		$mailer->Subject = $subject;
		
		
		
		$emailall=$to;

		$semail=explode(",",$emailall);
		foreach($semail as $emailadd)
		{
			$mailer->AddAddress($emailadd);  
			
		}
		
	
		if($bcc!=""){
			$bccall=$bcc;
			
			
			$sbcc=explode(",",$bccall);
			foreach($sbcc as $bccadd)
			{
				$mailer->AddBCC($bccadd);  // This is where you put the email adress of the person you want to mail
				
			}
		}
		
		
		$attempt=0;
		
		
		while(!$mailer->Send())
		{
		   if($attempt==3)
		   {
		   		echo "<script>window.location='os_invalid.php?attempt=$attempt&back=1&error=4&errormsg=".$mailer->ErrorInfo."';</script>";
		   		die();
		   }
		    $attempt++;
		}

	}
	
	
	
	function email_invoice($id)
	{
		$get_bill=mysql_query("select * from os_bill_details where id=$id");
		$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
		$get_item=mysql_query("select * from os_bill_items where bid=$id and addon_for=0")or die("line 11".mysql_error());
		$count=mysql_num_rows($get_bill);
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];
		
		$get_bank=mysql_query("select * from os_bankacc where id=1");
		$bank=mysql_fetch_array($get_bank,MYSQL_ASSOC);
				
		$to=$b['email'];
		$subject=$websitename_eng." Purchase Invoice";
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Invoice");
		$body.="
			<table width='100%'>
				<tr>
					<Td>
						<table align='right' width='60%' class='text'> 
							<tr align='left'>
								<td width='30%'>Invoice number</td><td width='1%'>:</td><td width='50%'>".$b['invoice_number']."	</td>
							</tr>
							<tr align='left'>
								<td width='30%'>Order number</td><td width='1%'>:</td><td width='50%'>".$b['order_request_number']."	</td>
							</tr>
							
							<tr>
								<td align='left'>To:</td>
							</tr>";
							
							
							if($b['state']!=0)
							{
								$get_place=mysql_query('select * from os_state where id='.$b['state'])or die(mysql_error());
								$place=mysql_result($get_place,0,'name_eng');
								$state=$place;
							}
							else
							{
								$state='-';
							}
							
							if($b['country']!=0)
							{
							
								$get_country=mysql_query('select * from os_country where id='.$b['country'])or die(mysql_error());
								$country=mysql_result($get_country,0,'engname');
								$word_country=$country;
							}
							else
							{
								$word_country='Other';
							} 
									
							$body.="
							<tr>
								<td colspan='3' align='left'>
								".$b['receiver_name']."
								<br>
								".$b['email']."
								<br>
								".$b['address1']."
								<br>
								".$b['address2']."
								<br>
								".$b['city']."
								<br>
								".$b['postcode']."
								<br>
								".$state."
								<br>
								".$word_country."
								</td>
							</tr>
							<tr>
								<td></td>
							</tr>
							
					  </table>
					
					</td>
				</tr>
				<tr>
					<td colspan='2'>
						<table width='90%' bgcolor='#CCCCCC' cellpadding='1' cellspacing='1' class='text' align=center>";
						
						$body.="<tr bgcolor='#F3F3F3' align='center'>
						<td width='42%'>Product</td><td width='13%'>Price(".$_SESSION['module_currency_display'].")</td><td width='15%'>Product code</td><td width='11%'>Quantity</td><td width='15%'>Total(".$_SESSION['module_currency_display'].")</td>
						</tr>";
						$colspan="4";
						
							
							
						
						$total_item=0;
						$total_piece=0;
						$total_allprice=0;
						while($c=mysql_fetch_array($get_item))
						{
							$total_price=0;
							$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$c['item_id']);
							$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
							$total_price=$a['unit_price']*$c['quantity'];
							$total_allprice=$total_allprice+$total_price;
									
							if($b['is_redeem']==1)
							{
								$body.="<tr bgcolor='#FFFFFF' align='center'>
									<td align='left'>".$a['product_name_eng']." [".$c['redeemed_points']." points used]<br>Product Option : <strong>".$a['description']."</strong></td>
									<td>".$a['unit_price']."</td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
									<td align='right'>".number_format($total_price,2)."</td> 
								</tr>";
								
							}
							else
							{
						
								$body.="<tr bgcolor='#FFFFFF' align='center'>
									<td align='left'>".$a['product_name_eng']."<br>Product Option : <strong>".$a['description']."</strong></td>
									<td>".$a['unit_price']."</td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
									<td align='right'>".number_format($total_price,2)."</td> 
								</tr>";
								
							}	
							
							$get_addon=mysql_query("select * from os_bill_items where addon_for='".$c['id']."'")or die(mysql_error());
				
							if(mysql_num_rows($get_addon)>0)
							{
						
							 $body.="<tr height='30' valign='top' bgcolor='#FFFFFF' >
								  <td colspan='6' valign='middle'>
									 <strong> Add-on(s)</strong>
								  </td>									
							 </tr>";
						
							
								while($addon=mysql_fetch_assoc($get_addon))
								{
									$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$addon['item_id']);
									$ap=mysql_fetch_array($get_product,MYSQL_ASSOC);
									$total_price=$ap['unit_price']*$addon['quantity'];
									
								   $body.="<tr height='30' valign='top'  align='center' bgcolor='#cccccc'>
										<td align='left'>".$ap['product_name_eng']."
										</td><td>".$ap['unit_price']."</td><td>".$ap['product_code']."</td><td>".$addon['quantity']."</td>
										<td align='right'>".number_format($total_price,2)."</td>
									</tr>";
								
									
								}
							}				
						} 
						
						$total_amount=$b['total_amount']; 
						$discount=($b['discount']/100)*$total_amount;
						$final_amount=($total_amount-$discount)+$b['transport_fees'];
						
						
								
					
						
						
						$get_voucher=mysql_query("select * from os_discount_voucher_used where bill_id=$id")or die(mysql_error());
									
						if(mysql_num_rows($get_voucher)>0)
						{
							
							$voucher=mysql_query("select * from os_discount_voucher where id='".mysql_result($get_voucher,0,"voucher_id")."'")or die(mysql_error());
			
							$v=mysql_fetch_array($voucher,MYSQL_ASSOC);
							
							if($v['discount_type']=="P")
							{
								$desc=number_format($v['discount_amount'],0)."% off";
								$discount=($total_allprice*$v['discount_amount'])/100;
								
								$final_amount=$final_amount-$discount;
							}
							else
							{
								$desc=$_SESSION['module_currency_display']."".$v['discount_amount']." off";
								$discount=$v['discount_amount'];
								$final_amount=$final_amount-$v['discount_amount'];
							}
							
							
				
				   
							$body.="<tr bocolor='#FFFFFF'>
									<td colspan='$colspan' align='right' bgcolor='#FFFFFF'> Discount voucher used : ".$v['voucher_name']." (".$v['voucher_code'].") ".$desc." </td><td  bgcolor='#FFFFFF' align='right'> -".number_format($discount,2)."</td></tr>";
				
							
						}
						$body.="
						<tr bgcolor='#FFFFFF'>
							<td colspan='$colspan' align='right' bgcolor='#FFFFFF'> Discount </td><td align='right'>- ".$b['discount']."%</td>
						</tr>
						<tr bgcolor='#FFFFFF'>
							<td colspan='$colspan' align='right' > Shipment Fee</td><td align='right'>".number_format($b['transport_fees'],2)."</td>
						</tr>
						
						<tr bgcolor='#FFFFFF'>
							<td colspan='$colspan' align='right' bgcolor='#FFFFFF'> Grand Total </td><td align='right'>".number_format($final_amount,2)."</td>
						</tr>
						</table>
					
					</td>
				</tr>
				<tr>
					<td align='left' colspan=2>";
					
							$dayleft=3-dayDiff($b['verified_date']);
							$timeStamp = strtotime($b['verified_date']);
							$timeStamp += 24 * 60 * 60 * $dayleft; 
							$expiryDate = date('Y-m-d', $timeStamp);
					
						$body.="<br><br>
						
						- Once payment has been made, kindly make a payment record through our online store. <br>
						- You may also inform us by replying to this email and attaching along the supporting documents (e.g. scanned ATM deposit slip, printscreen of e-banking transaction, etc) <br>
						- This invoice will be invalid after 3 days and your order will be voided from the system.<br>
						<br>
						<br>
						Kindly make payment to the following:
						<br>
						<table cellpadding='1' cellspacing='1' align='left' >
							<tr align='left'><td>Bank</td><td>:</td><td>".$bank['bank_name']."</td></tr>
							<tr align='left'><td>Company Name</td><td>:</td><td>".$bank['acc_name']."</td></tr>
							<tr align='left'><td>Acc. Number</td><td>:</td><td>".$bank['acc_no']."</td></tr>
						</table>
						 
						
					</td>
				</tr>
				<tr>
					<td colspan=2>Note: This email will serve as an official invoice for this payment.
					
				</tr>
				
				</table>
			</td>
		</tr>
	</table>
			
	";
	
	$body.=email_footer($os_url);
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);

	
}


function email_vip_member_register($id,$activatecode)
{
		$code=generatePassword();
		$enid=(($id+$code)-983421)*(-25);
		
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];
		
		$get_member=mysql_query("select * from os_member where id=$id");		
		$m=mysql_fetch_array($get_member,MYSQL_ASSOC);
		
		$to=$m['email'];
		$email=$m['email'];
		$password=$m['password'];
		$name=$m['name'];
		
		$get_bank=mysql_query("select * from os_bankacc where id=1");
		$bank=mysql_fetch_array($get_bank,MYSQL_ASSOC);

		$subject=$websitename_eng." Member Activation";
		
		//-----------------------------------Body begin----------------------------
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Member Registration");
		$body.="
		
				<table width='80%' style='border:1px #999999 solid' align='center'>
				
				<td width='100%'>
				<table align='center' bgcolor='#FFFFFF'>
				<tr>
							<td>
								
								Dear $name,<br><br>
								Thank you for joining as an online member. Please click the link below to activate your member account.<br><br>
								<a href='$os_url/memberactivate.php?activatecode=$activatecode&id=$enid&dbase=$code'>Activate Account</a>
									
							</td>
				</tr>
				
				<tr>
							<td>
								<hr style='border:1px dashed black;height:1px'>
								The information below are the details to your account login. Please do not share this information with a third party.
								<br><br>
								Email : $email<br>
								Password : $password
								
									
							</td>
				</tr>
				<Tr>
					<td>
					<br>
					To activate your VIP member account, Kindly make payment <strong>(".$_SESSION['module_currency_display']."10)</strong> to the following:<br>
					<table cellpadding='1' cellspacing='1' align='left' width='40%'>
						<tr align='left'><td>Bank</td><td>:</td><td>".$bank['bank_name']."</td></tr>
						<tr align='left'><td>Company Name</td><td>:</td><td>".$bank['acc_name']."</td></tr>
						<tr align='left'><td>Acc. Number</td><td>:</td><td>".$bank['acc_no']."</td></tr>
					</table>
					
				
					</td>
				</tr>
				<tr>
					<td>	
					- Once payment has been made, kindly inform us by replying to this email and attaching along the supporting documents (e.g. scanned ATM deposit slip, printscreen of e-banking transaction, etc) <br>
					- Or fax to ".$i['fax'].".
				</tr>
				</table>
				</td>
				</table>
		";
	
	$body.=email_footer($os_url);
	
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);

	
}

function email_normal_member_register($id,$activatecode)
{
		$code=generatePassword();
		$enid=(($id+$code)-983421)*(-25);
		
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];
		
		$get_member=mysql_query("select * from os_member where id=$id");		
		$m=mysql_fetch_array($get_member,MYSQL_ASSOC);
		
		$to=$m['email'];
		$email=$m['email'];
		$password=$m['password'];
		$name=$m['name'];
		

		$subject=$websitename_eng." Member Activation";
		
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Member Registration");
		$body.="
		
				<table width='80%' style='border:1px #999999 solid' align='center'>
				
				<td width='100%'>
				<table align='center' bgcolor='#FFFFFF'>
				<tr>
							<td>
								
								Dear $name,<br><br>
								Thank you for joining as an online member. Please click the link below to activate your member account.<br><br>
								<a href='$os_url/memberactivate.php?activatecode=$activatecode&id=$enid&dbase=$code'>Activate Account</a>
									
							</td>
				</tr>
				
				<tr>
							<td>
								<hr style='border:1px dashed black;height:1px'>
								The information below are the details to your account login. Please do not share this information with a third party.
								<br><br>
								Email : $email<br>
								Password : $password
								
									
							</td>
				</tr>
				</table>
				</td>
				</table>
		";
	
	$body.=email_footer($os_url);
	
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);

	
}	
	
function email_discount_voucher($member_id,$voucher_id)
{		
	$get_info=mysql_query("select * from os_contactinfo where id=1");
	$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
	$websitename_eng=$i['website_name'];
	$logo_url=$i['logo_url'];
	$os_url=$i['website'];
	$from_email=$i['email'];
	$bcc="";	
	
	$get_voucher=mysql_query("select * from os_discount_voucher where id=$voucher_id");	
	$get_member=mysql_query("select * from os_member where id=$member_id");		
	if(mysql_num_rows($get_voucher)>0 and mysql_num_rows($get_member)>0)
	{	
		$v=mysql_fetch_array($get_voucher,MYSQL_ASSOC);
		
		
		$m=mysql_fetch_array($get_member,MYSQL_ASSOC);
		
		for($c=0;$c<$v['times_to_use'];$c++)
		{
			mysql_query("insert into os_discount_voucher_used(member_id,voucher_id,is_birthday_voucher,status)values('$member_id','$voucher_id',0,0)")or die(mysql_error());
		}
		
		$to=$m['email'];
		$email=$m['email'];
		$name=$m['name'];
		
		$email_content=$v['email_content'];
		$email_subject=$v['email_subject'];
		
		$keyword=array("[%name%]","[%email%]","[%voucher_code%]","[%birdth_date%]","[%expiry_date%]","[%minimum_purchase%]");
		$replace=array($name,$email,$v['voucher_code'],$m['dob'],$v['end_date'],$v['minimum_purchase']);
				
		$new_content=str_replace($keyword, $replace, $email_content);
		
		$subject=str_replace($keyword, $replace, $email_subject);
		
		
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Discount Voucher");
		$body.="
				<table width='80%' style='border:1px #999999 solid' align='center'>
					<tr>
						<td align='center'><img src='$logo_url'></td>
					</tr>
					<td>
						$new_content	
					</td>
					<tr>
						<td><a href='$os_url'>Go to $websitename_eng now</a></td>
					</tr>	
				</table>
				
			";
	
	$body.=email_footer($os_url);
	
		email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);
	}
}

function email_birthday_voucher($member_id,$voucher_id)
{		
	$get_info=mysql_query("select * from os_contactinfo where id=1");
	$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
	$websitename_eng=$i['website_name'];
	$logo_url=$i['logo_url'];
	$os_url=$i['website'];
	$from_email=$i['email'];
	$bcc="";	
	
	$get_voucher=mysql_query("select * from os_discount_voucher where id=$voucher_id");	
	$get_member=mysql_query("select * from os_member where id=$member_id");		
	
	if(mysql_num_rows($get_voucher)>0 and mysql_num_rows($get_member)>0)
	{	
		$v=mysql_fetch_array($get_voucher,MYSQL_ASSOC);
			
		$m=mysql_fetch_array($get_member,MYSQL_ASSOC);
		
		
		$to=$m['email'];
		$email=$m['email'];
		$name=$m['name'];
		
		$email_content=$v['email_content'];
		$email_subject=$v['email_subject'];
		
		$keyword=array("[%name%]","[%email%]","[%voucher_code%]","[%birdth_date%]","[%expiry_date%]","[%minimum_purchase%]");
		$replace=array($name,$email,$v['voucher_code'],$m['dob'],$v['end_date'],$v['minimum_purchase']);
				
		$new_content=str_replace($keyword, $replace, $email_content);
		
		$subject=str_replace($keyword, $replace, $email_subject);
		
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Birthday Voucher");
		$body.="
				<table width='80%' style='border:1px #999999 solid' align='center'>
					<tr>
						<td align='center'><img src='$logo_url'></td>
					</tr>
					<td>
						$new_content	
					</td>
					<tr>
						<td><a href='$os_url'>Go to $websitename_eng now</a></td>
					</tr>	
				</table>
				
			";
	
	$body.=email_footer($os_url);
	
		email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);
	}
}


function email_forgot_password($email,$password)
{
		
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];
		
		
		$subject=$websitename_eng." - retrieve password";
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Retrieve Password");
		$body.="
		<table>
		<tr>
			<td align='center'><img src='$logo_url'></td>
		</tr>
		<tr>
			<td>
				
				Dear Member,below is the password we retrieved for your request.<br>
				Email: $email<br>
				Password: $password.<br><br>
				<a href='$os_url'>Enter $websitename_eng website now</a>	
			</td>
		</tr>
		</table>
		";
	
	$body.=email_footer($os_url);
		//-------------------------------- end of body ---------------------------------
	
	email_send($body,$email,$bcc,$subject,$websitename_eng,$from_email);

	
}

function email_unlock_abfs($unlock_code)
{
		
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$admin_panel_url=$i['admin_panel_url'];
		$from_email=$i['email'];
		$bcc="";
		$to=$i['email_security'];
		
		$subject=$websitename_eng." - Unlock ABFS";
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Unlock ABFS");
		$body.="
		<table>
		<tr>
			<td align='center'><img src='$logo_url'></td>
		</tr>
		<tr>
			<td>
				
				Please click the link below to unlock.<br>
				<a href='$admin_panel_url/abfs_unlock.php?token=$unlock_code'>Unlock ABFS</a>
				
			</td>
		</tr>
		</table>
		";
	
	$body.=email_footer($os_url);
		//-------------------------------- end of body ---------------------------------
	
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);

	
}
	


	
	function email_orderrequest($id)
	{
		$get_bill=mysql_query("select * from os_bill_details where id=$id");
		$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
		$get_item=mysql_query("select * from os_bill_items where bid=$id and addon_for=0")or die("line 11".mysql_error());
		$count=mysql_num_rows($get_bill);
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];
		
		$get_bank=mysql_query("select * from os_bankacc where id=1");
		$bank=mysql_fetch_array($get_bank,MYSQL_ASSOC);
				
		$to=$b['email'];
		$subject=$websitename_eng." Order Request";
		$body=email_header($os_url,$logo_url,$i['website_name'],$i['contact_number'],$i['fax'],"Order Request");
		$body.="
			
			<table align='right' width='60%' class='text'> 
				<tr align='left'>
					<td width='65%'>Order number</td><td width='1%'>:</td><td width='34%'>".$b['order_request_number']."	</td>
				</tr>
				<tr  align='left'>
					<td width='65%'>Order date</td><td width='1%'>:</td><td width='34%'>".$b['create_date']."</td>
				</tr>
				<tr>
					<td align='left'>To:</td>
				</tr>";
				
				
				if($b['state']!=0)
				{
					$get_place=mysql_query('select * from os_state where id='.$b['state'])or die(mysql_error());
					$place=mysql_result($get_place,0,'name_eng');
					$state=$place;
				}
				else
				{
					$state='-';
				}
				
				if($b['country']!=0)
				{
				
					$get_country=mysql_query('select * from os_country where id='.$b['country'])or die(mysql_error());
					$country=mysql_result($get_country,0,'engname');
					$word_country=$country;
				}
				else
				{
					$word_country='Other';
				} 
						
				$body.="
				<tr>
					<td colspan='3' align='left'>
					".$b['receiver_name']."
					<br>
					".$b['email']."
					<br>
					".$b['address1']."
					<br>
					".$b['address2']."
					<br>
					".$b['city']."
					<br>
					".$b['postcode']."
					<br>
					".$state."
					<br>
					".$word_country."
					</td>
				</tr>
				<tr>
					<td></td>
				</tr>
				
		  </table>
		
		</td>
	</tr>
	<tr>
		<td colspan='2'>
			<table width='95%' bgcolor='#CCCCCC' cellpadding='1' cellspacing='1' class='text' align=center>";
				if($b['is_redeem']==1)
				{
					$body.="<tr bgcolor='#F3F3F3' align='left'>
					<td width='42%'>Product</td><td width='15%'>Product code</td><td width='11%'>Quantity </td><td width='15%'>Points Used</td>
					</tr>";
					$colspan="3";
				}
				else
				{	
					$body.="<tr bgcolor='#F3F3F3' align='left'>
					<td width='42%'>Product</td><td width='13%'>Price(".$_SESSION['module_currency_display'].")</td><td width='15%'>Product code</td><td width='11%'>Quantity</td><td width='15%'>Total(".$_SESSION['module_currency_display'].")</td>
					</tr>";
					$colspan="4";
			 	}
				
			
			$total_item=0;
			$total_piece=0;
			$total_allprice=0;
			while($c=mysql_fetch_array($get_item))
			{
				$total_price=0;
				$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$c['item_id']);
				$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
				$total_price=$a['unit_price']*$c['quantity'];
				$total_allprice=$total_allprice+$total_price;
						
				if($b['is_redeem']==1)
				{
					$body.="<tr bgcolor='#FFFFFF' align='center'>
						<td align='left'>".$a['product_name_eng']."
					<br>Product Option : <strong>".$a['description']."</strong></td>
					<td>".$a['product_code']."</td>
					<td>".$c['quantity']."</td>
					<td>".$c['redeemed_points']."</td>";
					
				}
				else
				{
			
					$body.="<tr bgcolor='#FFFFFF' align='left'>
						<td>".$a['product_name_eng']."<br>Product Option : <strong>".$a['description']."</strong></td>
						<td>".$a['unit_price']."</td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
						<td align='right'>".number_format($total_price,2)."</td> 
					</tr>";
					
				}	
			
				$get_addon=mysql_query("select * from os_bill_items where addon_for='".$c['id']."'")or die(mysql_error());
				
				if(mysql_num_rows($get_addon)>0)
				{
			
				 $body.="<tr height='30' valign='top' bgcolor='#FFFFFF'>
					  <td colspan='6' valign='middle'>
						 <strong> Add-on(s)</strong>
					  </td>									
				 </tr>";
			
				
					while($addon=mysql_fetch_assoc($get_addon))
					{
						$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$addon['item_id']);
						$ap=mysql_fetch_array($get_product,MYSQL_ASSOC);
						$total_price=$ap['unit_price']*$addon['quantity'];
						
                       $body.="<tr height='30' valign='top'  align='center' bgcolor='#cccccc'>
							<td align='left'>".$ap['product_name_eng']."
							</td><td>".$ap['unit_price']."</td><td>".$ap['product_code']."</td><td>".$addon['quantity']."</td>
							<td align='right'>".number_format($total_price,2)."</td>
						</tr>";
					
						
					}
				}		
							
			} 

			$total_amount=$b['total_amount']; 
			$discount=($b['discount']/100)*$total_amount;
			$final_amount=($total_amount-$discount)+$b['transport_fees'];
			
			$get_voucher=mysql_query("select * from os_discount_voucher_used where bill_id=$id")or die(mysql_error());
						
			if(mysql_num_rows($get_voucher)>0)
			{
				
				$voucher=mysql_query("select * from os_discount_voucher where id='".mysql_result($get_voucher,0,"voucher_id")."'")or die(mysql_error());

				$v=mysql_fetch_array($voucher,MYSQL_ASSOC);
				
				if($v['discount_type']=="P")
				{
					$desc=number_format($v['discount_amount'],0)."% off";
					$discount=($total_allprice*$v['discount_amount'])/100;
					
					$final_amount=$final_amount-$discount;
				}
				else
				{
					$desc=$_SESSION['module_currency_display']."".$v['discount_amount']." off";
					$discount=$v['discount_amount'];
					$final_amount=$final_amount-$v['discount_amount'];
				}
				
				
	
	   
				$body.="<tr bocolor='#FFFFFF'>
						<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Discount voucher used : ".$v['voucher_name']." (".$v['voucher_code'].") ".$desc."</td><td  bgcolor='#FFFFFF' align='right'> -".number_format($discount,2)."</td></tr>";
	
				
			}
					
			

					
			$body.="
				<tr bgcolor='#FFFFFF'>
					<td colspan='$colspan' align='right' bgcolor='#FFFFFF'> Discount </td><td align='right'>- ".$b['discount']."%</td>
				</tr>
				<tr bgcolor='#FFFFFF'>
					<td colspan='$colspan' align='right' > Shipment Fee</td><td align='right'>".number_format($b['transport_fees'],2)."</td>
				</tr>
				<tr bgcolor='#FFFFFF'>
					<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Subtotal</td><td align='right'>".number_format($final_amount,2)."</td>
				</tr>
			</table>
		
		</td>
	</tr>
	<tr>
		<td align='left' colspan=2>";
			$body.="<br><br>
			
			-	Your order is being processed and you shall be contacted soon. <br>
			-	If you have further enquiry, please feel free to contact us at any time.<br>
			-	Thank you for purchasing<br>

			
		</td>
	</tr>
	
	
	</table>
	
	";
	
	$body.=email_footer($os_url);
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);
}
	
	
	
	
	
	
	
	
	
	function email_shipmentinfo($id)
	{
		$get_bill=mysql_query("select * from os_bill_details where id=$id");
		$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
		$get_item=mysql_query("select * from os_bill_items where bid=$id and addon_for=0")or die("line 11".mysql_error());
		$count=mysql_num_rows($get_bill);
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];		
		$to=$b['email'];
		
		$subject=$websitename_eng." Courier Info";
		
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax']," Courier Information");
		$body.="
	<table width='100%'>
				<tr>
					<Td>
			<table align='right' width='60%' class='text'> 
				<tr align='left'>
					<td width='30%'>Courier number</td><td width='1%'>:</td><td width='50%'>".$b['courier_number']."	</td>
				</tr>
				<tr align='left'>
					<td width='30%'>Order number</td><td width='1%'>:</td><td width='50%'>".$b['invoice_number']."	</td>
				</tr>
				
				<tr>
					<td align='left'>To:</td>
				</tr>";
				
				
				if($b['state']!=0)
				{
					$get_place=mysql_query('select * from os_state where id='.$b['state'])or die(mysql_error());
					$place=mysql_result($get_place,0,'name_eng');
					$state=$place;
				}
				else
				{
					$state='-';
				}
				
				if($b['country']!=0)
				{
				
					$get_country=mysql_query('select * from os_country where id='.$b['country'])or die(mysql_error());
					$country=mysql_result($get_country,0,'engname');
					$word_country=$country;
				}
				else
				{
					$word_country='Other';
				} 
						
				$body.="
				<tr>
					<td colspan='3' align='left'>
					".$b['receiver_name']."
					<br>
					".$b['email']."
					<br>
					".$b['address1']."
					<br>
					".$b['address2']."
					<br>
					".$b['postcode']."
					<br>
					".$state."
					<br>
					".$word_country."
					</td>
				</tr>
				<tr>
					<td></td>
				</tr>
				
		  </table>
		
		</td>
	</tr>
	<tr>
		<td colspan='2' align='left'>
		Dear ".$b['receiver_name'].",<br>
		Thank you for choosing ".$websitename_eng.".
		<br><br>
			<u>The below item(s) has been sent via:</u>
			<br>
			<table width='100%'>
				<tr>
				<td width='30%'>Courier name</td><td width='1%'>:</td><td width='69%'>".$b['courier_name']."</td>
				</tr>
				<tr>
				<td width='30%'>Reference number</td><td width='1%'>:</td><td width='69%'>".$b['ref_no']."</td>
				</tr>
				<tr>
				<td width='30%'>Estimate Time of Arrival</td><td width='1%'>:</td><td width='69%'>".$b['eta']."</td>
				</tr>
			</table>
			<br>
			
			
			
			<table width='90%' bgcolor='#CCCCCC' cellpadding='1' cellspacing='1' class='text' align=center>
				<tr bgcolor='#F3F3F3' align='center'>
					<td width='39%'>Product</td><td width='19%'>Unit price(".$_SESSION['module_currency_display'].")</td><td width='14%'>Product code</td><td width='12%'>Quantity</td><td>Total (".$_SESSION['module_currency_display'].")</td>
				</tr>";
				
			
			$total_item=0;
			$total_piece=0;
			$total_allprice=0;
			while($c=mysql_fetch_array($get_item))
			{
				$total_price=0;
				$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$c['item_id']);
				$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
				$total_price=$a['unit_price']*$c['quantity'];
				$total_allprice=$total_allprice+$total_price;
						
																
			
				$body.="<tr bgcolor='#FFFFFF' align='center'>
											<td align='left'>".$a['product_name_eng']."</td><td>".$a['unit_price']."</td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
					<td align='right'>".number_format($total_price,2)."</td>
				</tr>";
				
				$get_addon=mysql_query("select * from os_bill_items where addon_for='".$c['id']."'")or die(mysql_error());
				
				if(mysql_num_rows($get_addon)>0)
				{
			
				 $body.="<tr height='30' valign='top' bgcolor='#FFFFFF'>
					  <td colspan='6' valign='middle'>
						 <strong> Add-on(s)</strong>
					  </td>									
				 </tr>";
			
				
					while($addon=mysql_fetch_assoc($get_addon))
					{
						$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$addon['item_id']);
						$ap=mysql_fetch_array($get_product,MYSQL_ASSOC);
						$total_price=$ap['unit_price']*$addon['quantity'];
						
                       $body.="<tr height='30' valign='top'  align='center' bgcolor='#cccccc'>
							<td align='left'>".$ap['product_name_eng']."
							</td><td>".$ap['unit_price']."</td><td>".$ap['product_code']."</td><td>".$addon['quantity']."</td>
							<td align='right'>".number_format($total_price,2)."</td>
						</tr>";
					
						
					}
				}						
			} 
					
			
			$body.="
			

			</table>
		
		</td>
	</tr>
	<tr>
		<td align='left' colspan=2>";
		
				$dayleft=7-dayDiff($b['verified_date']);
				$timeStamp = strtotime($b['verified_date']);
				$timeStamp += 24 * 60 * 60 * $dayleft; 
				$expiryDate = date('Y-m-d', $timeStamp);
		
			$body.="
		<tr>
		<td align=left colspan=2> Your order(s) will be delivered to the address which you have provided.
		</td>
	</tr>
	
	</table>
	</td>
	</tr>
	</table>
	";
	
	$body.=email_footer($os_url);
	
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);
}
	

	function email_receipt($id)
	{
		
		$get_bill=mysql_query("select * from os_bill_details where id=$id");
		$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
		$get_item=mysql_query("select * from os_bill_items where bid=$id and addon_for=0")or die("line 11".mysql_error());
		$count=mysql_num_rows($get_bill);
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];
		
		$get_bank=mysql_query("select * from os_bankacc where id=1");
		$bank=mysql_fetch_array($get_bank,MYSQL_ASSOC);
				
		$to=$b['email'];
		$subject=$websitename_eng." Payment Receipt";
		
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Receipt");
		$body.="
			<table width='100%'>
				<tr>
					<Td>
			<table align='right' width='60%' class='text'> 
				<tr align='left'>
					<td width='30%'>Receipt number</td><td width='1%'>:</td><td width='50%'>".$b['receipt_number']."	</td>
				</tr>
				<tr align='left'>
					<td width='30%'>Order number</td><td width='1%'>:</td><td width='50%'>".$b['order_request_number']."	</td>
				</tr>
				
				<tr>
					<td align='left'>To:</td>
				</tr>";
				
				
				if($b['state']!=0)
				{
					$get_place=mysql_query('select * from os_state where id='.$b['state'])or die(mysql_error());
					$place=mysql_result($get_place,0,'name_eng');
					$state=$place;
				}
				else
				{
					$state='-';
				}
				
				if($b['country']!=0)
				{
				
					$get_country=mysql_query('select * from os_country where id='.$b['country'])or die(mysql_error());
					$country=mysql_result($get_country,0,'engname');
					$word_country=$country;
				}
				else
				{
					$word_country='Other';
				} 
						
				$body.="
				<tr>
					<td colspan='3' align='left'>
					".$b['receiver_name']."
					<br>
					".$b['email']."
					<br>
					".$b['address1']."
					<br>
					".$b['address2']."
					<br>
					".$b['city']."
					<br>
					".$b['postcode']."
					<br>
					".$state."
					<br>
					".$word_country."
					</td>
				</tr>
				<tr>
					<td></td>
				</tr>
				
		  </table>
		
		</td>
	</tr>
	<tr>
		<td colspan='2' align='left'>
			Dear ".$b['receiver_name'].",<br>
			Thank you for your payment.
			<br><br>
						
			
			<table width='90%' bgcolor='#CCCCCC' cellpadding='1' cellspacing='1' class='text' align=center>";
				
			if($b['is_redeem']==1)
			{
				$body.="<tr bgcolor='#F3F3F3' align='center'>
				<td width='42%'>Product</td><td width='15%'>Product code</td><td width='11%'>Quantity </td><td width='15%'>Points Used</td>
				</tr>";
				$colspan="3";
			}else{	
				$body.="<tr bgcolor='#F3F3F3' align='center'>
				<td width='42%'>Product</td><td width='13%'>Price(".$_SESSION['module_currency_display'].")</td><td width='15%'>Product code</td><td width='11%'>Quantity</td><td width='15%'>Total(".$_SESSION['module_currency_display'].")</td>
				</tr>";
				$colspan="4";
			 }
			 
			$total_item=0;
			$total_piece=0;
			$total_allprice=0;
			while($c=mysql_fetch_array($get_item))
			{
				$total_price=0;
				$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$c['item_id']);
				$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
				$total_price=$a['unit_price']*$c['quantity'];
				$total_allprice=$total_allprice+$total_price;
						
																
			
				if($b['is_redeem']==1)
				{
					$body.="<tr bgcolor='#FFFFFF' align='center'>
					<td align='left'>".$a['product_name_eng']."
					<br>Product Option : <strong>".$a['description']."</strong></td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
					<td>".$c['redeemed_points']."</td>";
					
				}
				else
				{
			
					$body.="<tr bgcolor='#FFFFFF' align='center'>
						<td align='left'>".$a['product_name_eng']."<br>Product Option : <strong>".$a['description']."</strong></td>
						<td>".$a['unit_price']."</td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
						<td align='right'>".number_format($total_price,2)."</td> 
					</tr>";
					
				}
				
				$get_addon=mysql_query("select * from os_bill_items where addon_for='".$c['id']."'")or die(mysql_error());
				
				if(mysql_num_rows($get_addon)>0)
				{
			
				 $body.="<tr height='30' valign='top' bgcolor='#FFFFFF'>
					  <td colspan='6' valign='middle'>
						 <strong> Add-on(s)</strong>
					  </td>									
				 </tr>";
			
				
					while($addon=mysql_fetch_assoc($get_addon))
					{
						$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$addon['item_id']);
						$ap=mysql_fetch_array($get_product,MYSQL_ASSOC);
						$total_price=$ap['unit_price']*$addon['quantity'];
						
                       $body.="<tr height='30' valign='top'  align='center' bgcolor='#cccccc'>
							<td align='left'>".$ap['product_name_eng']."
							</td><td>".$ap['unit_price']."</td><td>".$ap['product_code']."</td><td>".$addon['quantity']."</td>
							<td align='right'>".number_format($total_price,2)."</td>
						</tr>";
					
						
					}
				}					
							
			} 
					$total_amount=$b['total_amount']; 
					$discount=($b['discount']/100)*$total_amount;
					$final_amount=($total_amount-$discount)+$b['transport_fees'];
			
			$body.="
			<tr bgcolor='#FFFFFF'>
				<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Discount</td><td align='right'>- ".$b['discount']."%</td>
			</tr>
			<tr bgcolor='#FFFFFF'>
				<td colspan='$colspan' align='right' >Shipment Fee</td><td align='right'>".number_format($b['transport_fees'],2)."</td>
			</tr>
			";
			
			$get_voucher=mysql_query("select * from os_discount_voucher_used where bill_id=$id")or die(mysql_error());
						
			if(mysql_num_rows($get_voucher)>0)
			{
				
				$voucher=mysql_query("select * from os_discount_voucher where id='".mysql_result($get_voucher,0,"voucher_id")."'")or die(mysql_error());

				$v=mysql_fetch_array($voucher,MYSQL_ASSOC);
				
				if($v['discount_type']=="P")
				{
					$desc=number_format($v['discount_amount'],0)."% off";
					$discount=($total_allprice*$v['discount_amount'])/100;
					
					$final_amount=$final_amount-$discount;
				}
				else
				{
					$desc=$_SESSION['module_currency_display']."".$v['discount_amount']." off";
					$discount=$v['discount_amount'];
					$final_amount=$final_amount-$v['discount_amount'];
				}
	
	   
				$body.="<tr bocolor='#FFFFFF'>
						<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Discount voucher used : ".$v['voucher_name']." (".$v['voucher_code'].") ".$desc." </td><td  bgcolor='#FFFFFF' align='right'> -".number_format($discount,2)."</td></tr>";
	
				
			}
			
			$body.="<tr bgcolor='#FFFFFF'>
				<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Grand Total</td><td align='right'>".number_format($final_amount,2)."</td>
			</tr>
			<tr bgcolor='#FFFFFF'>
				<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Amount Paid</td><td align='right'>".number_format($final_amount,2)."</td>
			</tr>

			</table>
		
		</td>
	</tr>
	<tr>
		<td align='left'>";
		
				$dayleft=7-dayDiff($b['verified_date']);
				$timeStamp = strtotime($b['verified_date']);
				$timeStamp += 24 * 60 * 60 * $dayleft; 
				$expiryDate = date('Y-m-d', $timeStamp);
		
			$body.="
		<tr>
		<td align=left colspan=2>
		- Your order(s) will be delivered to the address which you have provided. <br>
		- You will receive an update on the delivery of your purchase(s) soon. <br>
		- If you are a C.O.D customer, kindly ignore the messages above and accept this email as an official receipt.<br>
		- Kindly contact us if you have any enquiries. <br>
		- We would deeply appreciate if you would inform us once you have received your order(s). Please <a href='$os_url/os_contact.php'>click here</a> to inform us.

		<br>
		

		</td>
	</tr>
	
	</table>
	</td>
	</tr>
	</table>
	";
	
	$body.=email_footer($os_url);
	
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);
}
	
	
	
	
	
	function email_payment_notice($id,$pid)
	{		
		$get_bill=mysql_query("select * from os_bill_details where id=$id");
		$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
		$get_item=mysql_query("select * from os_bill_items where bid=$id and addon_for=0")or die("line 11".mysql_error());
		$count=mysql_num_rows($get_bill);
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$bcc=$i['email_hidden'];
		$from_email=$i['email'];
		
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		
		$get_payment=mysql_query("select * from os_payment_record where id=$pid");
		$p=mysql_fetch_array($get_payment,MYSQL_ASSOC);
		//$to="desmond@deswin.com.my";		
		$to=$i['email_hidden'];
		$subject=$websitename_eng." Paymemt Notification : ".$b['invoice_number'];
		
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Payment Notice");
		$body.="
		<table width='100%'>
				<tr>
					<Td>
	
			<table align='right' width='60%' class='text'> 
				<tr align='left'>
					<td width='65%'>Invoice number</td><td width='1%'>:</td><td width='34%'>".$b['invoice_number']."	</td>
				</tr>
				<tr  align='left'>
					<td width='65%'>Invoice date</td><td width='1%'>:</td><td width='34%'>".$b['create_date']."</td>
				</tr>
				<tr>
					<td align='left'>Buyer Info:</td>
				</tr>";
				
				
				if($b['state']!=0)
				{
					$get_place=mysql_query('select * from os_state where id='.$b['state'])or die(mysql_error());
					$place=mysql_result($get_place,0,'name_eng');
					$state=$place;
				}
				else
				{
					$state='-';
				}
				
				if($b['country']!=0)
				{
				
					$get_country=mysql_query('select * from os_country where id='.$b['country'])or die(mysql_error());
					$country=mysql_result($get_country,0,'engname');
					$word_country=$country;
				}
				else
				{
					$word_country='Other';
				} 
						
				$body.="
				<tr>
					<td colspan='3' align='left'>
					".$b['receiver_name']."
					<br>
					".$b['email']."
					<br>
					".$b['address1']."
					<br>
					".$b['address2']."
					<br>
					".$b['postcode']."
					<br>
					".$state."
					<br>
					".$word_country."
					</td>
				</tr>
				<tr>
					<td></td>
				</tr>
				
		  </table>
		
		</td>
	</tr>
	<tr>
		<td colspan='2' align='left'>	
			
			<table width='90%' cellpadding='1' cellspacing='1' class='text' align=center>
				
			<tr>
				<td width='100%' align='left' style='solidborder'>
					<table width='100%'>
						<td colspan='6' bgcolor='#CCCCCC' ><b>Payment record </b></td>
						<tr align='left'>
							<td width='22%'>Payment date</td><td width='2%'>:</td><td width='18%'>".$p['paymentdate']."</td>
							<td width='20%'>Paid amount</td><td width='2%'>:</td><td width='36%'>".$_SESSION['module_currency_display']." ".number_format($p['paidamount'],2)."</td>
						</tr>
						<tr align='left'>
							<td>Bank</td><td>:</td><td>".$p['paymentbank'] ."</td>
							<td>Reference Number</td><td>:</td><td>".$p['accountnumber']."</td>
						</tr>
						<tr align='left'>
							<td >Remark</td><td>:</td ><td colspan='4'>".$p['message']."</td>
						</tr>
						<tr>
							
						</tr>
					</table>
				
				</td>
				
			</tr>

			</table>
		
		</td>
	</tr>
	
	</table>
	</td>
	</tr>
	</table>
	";
	
	$body.=email_footer($os_url);
	
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);
}
	
	
	function email_purchase_notice($id)
	{
		$websitename_eng="D Looking Glass";
		$logo_url="http://www.dlookingglass.com/images/logo.jpg";
		$os_url="http://www.dlookingglass.com"; 
		
		$get_bill=mysql_query("select * from os_bill_details where id=$id");
		$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
		$get_item=mysql_query("select * from os_bill_items where bid=$id and addon_for=0")or die("line 11".mysql_error());
		$count=mysql_num_rows($get_bill);
		$get_info=mysql_query("select * from os_contactinfo where id=1");
		$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
		$websitename_eng=$i['website_name'];
		$logo_url=$i['logo_url'];
		$os_url=$i['website'];
		$from_email=$i['email'];
		$bcc=$i['email_hidden'];
		$subject=$websitename_eng." Purchase Notification";
		
		$body=email_header($os_url,$logo_url,$websitename_eng,$i['contact_number'],$i['fax'],"Purchase Notice");
		$body.="
		<table width='100%'>
				<tr>
					<Td>
						<table width='600' bgcolor='#ffffff' align='center' style='border:1px solid #000000'>
						<tr valign='top'>
						<td align='right' colspan='2'><img src='$logo_url'></td>
						</tr>
						<tr>
							<td colspan='2' bgcolor='#666699' align='center' height='20'><font  style='color:#ffffff;font-size:14px;font-weight:bold'>Purchase Notification</font></td>
						</tr>
						<tr>
							<td colspan='2' align='right'>
								<table align='right' width='60%' class='text'> 
									<tr align='left'>
										<td width='65%'>Invoice number</td><td width='1%'>:</td><td width='34%'>".$b['invoice_number']."	</td>
									</tr>
									<tr  align='left'>
										<td width='65%'>Invoice date</td><td width='1%'>:</td><td width='34%'>".$b['create_date']."</td>
									</tr>
									<tr>
										<td align='left'>Buyer Info:</td>
									</tr>";
									
									
									if($b['state']!=0)
									{
										$get_place=mysql_query('select * from os_state where id='.$b['state'])or die(mysql_error());
										$place=mysql_result($get_place,0,'name_eng');
										$state=$place;
									}
									else
									{
										$state='-';
									}
									
									if($b['country']!=0)
									{
									
										$get_country=mysql_query('select * from os_country where id='.$b['country'])or die(mysql_error());
										$country=mysql_result($get_country,0,'engname');
										$word_country=$country;
									}
									else
									{
										$word_country='Other';
									} 
											
									$body.="
									<tr>
										<td colspan='3' align='left'>
										".$b['receiver_name']."
										<br>
										".$b['email']."
										<br>
										".$b['address1']."
										<br>
										".$b['address2']."
										<br>
										".$b['city']."
										<br>
										".$b['postcode']."
										<br>
										".$state."
										<br>
										".$word_country."
										</td>
									</tr>
									<tr>
										<td></td>
									</tr>
									
							  </table>
							
							</td>
						</tr>
						<tr>
							<td colspan='2' align='left'>
								Purchase Details<br>
							
								<table width='90%' bgcolor='#CCCCCC' cellpadding='1' cellspacing='1' class='text' align=center>";
									
								if($b['is_redeem']==1)
								{
									$body.="<tr bgcolor='#F3F3F3' align='center'>
									<td width='42%'>Product</td><td width='15%'>Product code</td><td width='11%'>Quantity </td><td width='15%'>Points Used</td>
									</tr>";
									$colspan="3";
								}else{	
									$body.="<tr bgcolor='#F3F3F3' align='center'>
									<td width='42%'>Product</td><td width='13%'>Price(".$_SESSION['module_currency_display'].")</td><td width='15%'>Product code</td><td width='11%'>Quantity</td><td width='15%'>Total(".$_SESSION['module_currency_display'].")</td>
									</tr>";
									$colspan="4";
								 }
									
								
								$total_item=0;
								$total_piece=0;
								$total_allprice=0;
								while($c=mysql_fetch_array($get_item))
								{
									$total_price=0;
									$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$c['item_id']);
									$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
									$total_price=$c['price']*$c['quantity'];
									$total_allprice=$total_allprice+$total_price;
											
									if($b['is_redeem']==1)
									{
										$body.="<tr bgcolor='#FFFFFF' align='center'>
											<td align='left'>".$a['product_name_eng']."
											<br>Product Option : <strong>".$a['description']."</strong></td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
											<td>".$c['redeemed_points']."</td></tr>";
									}
									else
									{			
										$body.="<tr bgcolor='#FFFFFF' align='center'>
											<td align='left'>".$a['product_name_eng']."<br>Product Option : <strong>".$a['description']."</strong></td>
											<td>".$a['unit_price']."</td><td>".$a['product_code']."</td><td>".$c['quantity']."</td>
											<td align='right'>".number_format($total_price,2)."</td></tr>";					
									}			
									$get_addon=mysql_query("select * from os_bill_items where addon_for='".$c['id']."'")or die(mysql_error());
									
									if(mysql_num_rows($get_addon)>0)
									{
								
									 $body.="<tr height='30' valign='top' bgcolor='#FFFFFF'>
										  <td colspan='6' valign='middle'>
											 <strong> Add-on(s)</strong>
										  </td>									
									 </tr>";
								
									
										while($addon=mysql_fetch_assoc($get_addon))
										{
											$get_product=mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=".$addon['item_id']);
											$ap=mysql_fetch_array($get_product,MYSQL_ASSOC);
											$total_price=$ap['unit_price']*$addon['quantity'];
											
										   $body.="<tr height='30' valign='top'  align='center' bgcolor='#cccccc'>
												<td align='left'>".$ap['product_name_eng']."</td><td>".$ap['unit_price']."</td><td>".$ap['product_code']."</td><td>".$addon['quantity']."</td>
												<td align='right'>".number_format($total_price,2)."</td>
											</tr>";
										
											
										}
									}					
												
								} 
										$total_amount=$b['total_amount']; 
										$discount=($b['discount']/100)*$total_amount;
										$final_amount=($total_amount-$discount)+$b['transport_fees'];
								
								$body.="
								
								<tr bgcolor='#FFFFFF'>
									<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Grand Total</td><td align='right'>".number_format($final_amount,2)."</td>
								</tr>
								<tr bgcolor='#FFFFFF'>
									<td colspan='$colspan' align='right' bgcolor='#FFFFFF'>Amount Paid</td><td align='right'>".number_format($final_amount,2)."</td>
								</tr>
					
								</table>
							
							</td>
						</tr>
						
						</table>
						</td>
						</tr>
						</table>
						";
	
	$body.=email_footer($os_url);
	
	email_send($body,$to,$bcc,$subject,$websitename_eng,$from_email);
}

?>